package main

import (
	"fmt"
	"time"
)

func main() {
	//无缓冲通道
	ch := make(chan int, 0)
	fmt.Printf("len(ch) = %d, cap(ch) = %d\n", len(ch), cap(ch))

	go func() {
		for i :=0; i < 3; i++ {
			fmt.Printf("子协程：i=%d\n", i)
			ch<-i	//写入chan
		}
	}()

	//延时
	time.Sleep(2*time.Second)
	for i:=0; i< 2;i++ {
		num := <-ch
		fmt.Println("num = ", num)
	}
}
